﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;

namespace UILocalization.ResourcesManager
{
    /// <summary>
    ///  Extended display attribute which will handles the request
    ///  It will call every time when the property is rendered (return View() - from controller)
    /// </summary>
    public class ResourceManagerAttribute : DisplayNameAttribute
    {
        public ResourceManagerAttribute(string resourceKey, string resourceNameSpace = "")
            : base(GetDisplayName(resourceKey, resourceNameSpace))
        { }

        private static string GetDisplayName(string resourceKey, string resourceNameSpace = "")
        {
            // get the browser's prefered language.

            string browserLanguage = HttpContext.Current.Request.UserLanguages.First();

            // Get the locale data for that property and displays.
            switch (browserLanguage)
            {
                case "en-US": return "Eng " + resourceKey;
                case "hi": return "Hin " + resourceKey;

            }
            return "-- Not Implemented Now -- ";
        }

    }
}